package com.qidian.mes.excel;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @Author 小可怎么都睡不够
 * @Description
 * @Time 2024-04-15 0:46
 */
public class ToolStatusConverter implements Converter<Integer> {

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 状态（1在库，2被领用，3报废，4维修中，99删除）
        return new WriteCellData<>(value == 1 ? "在库" : value == 2 ? "被领用" : value == 3 ? "报废" : value == 4 ? "维修中" : "删除");
    }

    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        String status = context.getReadCellData().getStringValue();
        // 状态（1在库，2被领用，3报废，4维修中，99删除）
        return status.equals("在库") ? 1 : status.equals("被领用") ? 2 : status.equals("报废") ? 3 : status.equals("维修中") ? 4 : 99;
    }
}
